<template>
  <a-modal v-model="visible" title="设置折扣" :width="700" centered @ok="handleSubmit" destroyOnClose class="return-modal">
    <a-form>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="设置折扣：" required>
        <a-input-number v-model="discount" :min="0.9" :max="1" :step="0.01" class="discount-input" placeholder="最小折扣0.9" :autoFocus="true" />
      </a-form-item>
      <div class="title">会员商场卡</div>
      <a-table :rowKey="record => record.id" :columns="columns" :data-source="data" :pagination="false"> </a-table>
    </a-form>
  </a-modal>
</template>
<script>
import { queryForBoxDiscount, setForBoxDiscount } from '@/api/box/order'
import { identity } from 'lodash'
const columns = [
  {
    title: '门店',
    dataIndex: 'name'
  },
  {
    title: '最低折扣',
    dataIndex: 'discount'
  }
]
export default {
  data() {
    this.columns = columns
    return {
      visible: false,
      labelCol: {
        xs: { span: 4 },
        sm: { span: 3 }
      },
      wrapperCol: {
        xs: { span: 12 },
        sm: { span: 12 }
      },
      discount: '',
      data: [],
      boxId: '',
      unionId: ''
    }
  },
  methods: {
    show(id, unionid) {
      this.boxId = id
      this.unionId = unionid
      this.visible = true
      this.fetchData()
    },
    fetchData() {
      let params = {
        requestData: {
          boxId: this.boxId,
          unionid: this.unionId
        },
        page: {
          pageNo: 1,
          pageSize: 100
        }
      }
      queryForBoxDiscount(params).then(res => {
        if (res.code == 0) {
          this.data = res.data
        } else {
          this.$message.warning(res.msg)
        }
      })
    },
    handleSubmit() {
      let params = {
        requestData: {
          boxId: this.boxId,
          shopDisount: this.discount
        }
      }
      setForBoxDiscount(params).then(res => {
        if (res.code == 0) {
          this.$message.success('设置成功！')
          this.visible = false
          this.$emit('updateDetail')
        } else {
          this.$message.warning(res.msg)
        }
      })
    }
  }
}
</script>
<style src="../less/modal.less" lang="less" scoped></style>
<style lang="less" scoped>
.discount-input {
  width: 40%;
  margin-right: 24px;
  cursor: default;
  color: rgba(0, 0, 0, 0.85);
}
</style>
